package dpsscorbainterface;



import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Scanner;

import org.omg.CORBA.ORB;
public class AdministratorClient extends Thread{

	
    public static void main(String args[]) throws RemoteException, NotBoundException, IOException{
    	ORB orb = ORB.init(args,null);
		
		BufferedReader br1 = new BufferedReader(new FileReader("ior1.txt"));
		String ior1 = br1.readLine();
		br1.close();
		
		org.omg.CORBA.Object o1 = orb.string_to_object(ior1);
		corbainterface NorthAmerica = corbainterfaceHelper.narrow(o1);
		
		BufferedReader br2 = new BufferedReader(new FileReader("ior2.txt"));
		String ior2 = br2.readLine();
		br2.close();
		
		org.omg.CORBA.Object o2 = orb.string_to_object(ior2);
		corbainterface Europe = corbainterfaceHelper.narrow(o2);
		
		
		BufferedReader br3 = new BufferedReader(new FileReader("ior3.txt"));
		String ior3 = br3.readLine();
		br3.close();
		
		org.omg.CORBA.Object o3 = orb.string_to_object(ior3);
		corbainterface Asia = corbainterfaceHelper.narrow(o3);
		
                   @SuppressWarnings("resource")
				Scanner scanner = new Scanner(System.in);
                       System.out.println("Enter username");
                        String User = scanner.next();
                        System.out.println("Enter Password");
                        String Pass = scanner.next() ;
                        System.out.println("Credentials are accepted, Welcome Admin.");
                        System.out.println("Enter 1 for Getting Player Status:");
                        System.out.println("Enter 2 for Suspending User:");
                       
                        String x = scanner.next();
                        if(User.equals("a") && Pass.equals("b"))
                        {
                        	
                        	if(x.equals("1")){
                                System.out.println("Enter IP address");
                            String IP = scanner.next();
                            if(IP.startsWith("132")){
                                NorthAmerica.getPlayerStatus(User, Pass, IP);
			          	 }else if(IP.startsWith("93")){
                            Europe.getPlayerStatus(User, Pass, IP);
                   }else if(IP.startsWith("182")){
                             Asia.getPlayerStatus(User, Pass, IP);
                   }
                        	}
                        	
                        	else if(x.equals("2")){
                        		System.out.println("Enter IP address");
                                String IP2 = scanner.next();
                                System.out.println("Enter Username to Suspend");
                                String Suspend = scanner.next();
                                if(IP2.startsWith("132"))
                                {
                                    NorthAmerica.suspendAccount(User, Pass, IP2, Suspend);
                                }
                                else if(IP2.startsWith("93"))
                                	{
                                Europe.suspendAccount(User, Pass, IP2, Suspend);
                                	}
                                	else 
                                		{
                                 Asia.suspendAccount(User, Pass, IP2, Suspend);
                                		}
                        	}
                        	
                        	else {System.out.println("Wrong credentials, try again!");
                        } 
                       }
            }
}
